<template>
    <div class="layerRtb layerRtb-threecolumn">
        <three-title :title="{name:'标准'}"></three-title>
        <div class="layerRtb-scroll thinScroll" v-scrollHeight="437">
            <div class="analyItem" v-for="(item, index) in this.pmStandards" :key="index">
                <p class="analyItemTit tx-center">标准</p>
                <div class="analyItemCon">
                    <p class="col-md-12">标题： <span class="cLightGray pr8">{{item.sdTitle}}</span> </p>
                    <p class="col-md-412">内容： <span class="cLightGray pr8">{{item.cdContent}}</span> </p>
                    <div stype="1" class="problemList">
                        <p class="fl col-md-12 mb10">
                            <select aid="15" name="set_pm_standard_user" pm_standard_user_sdid="30" spsuid="30" class="problemListStype1"  v-if="Number(item.sdId) === item.sdId" v-model="item.id"  @change="updatePmStandardUser(item)">
                                <option value="0">-请选择-</option>
                                <option value="1">{{item.stYou}}</option>
                                <option value="2">{{item.stLiang}}</option>
                                <option value="3">{{item.stZhong}}</option>
                                <option value="4">{{item.stCha}}</option>
                            </select>
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layerRtb-footer">
              <div class="analyItem">
                <p class="analyItemTit tx-center">综合</p>
                <div class="analyItemCon">
                    <p class="col-md-4">总分：<span class="cLightGray pr8">{{ Number(this.standards.length) > 0 ? 40 * this.pmStandards.length : 0 }}</span></p >
                    <p class="col-md-4">得分：<span class="cLightGray pr8">{{ Number(this.standards.length) > 0 ? this.scores : 0 }}</span></p >
                    <p class="fl">
                        <span v-if="Number(this.standards.length) === 0 || this.scores < (30 * this.pmStandards.length)" class="circlemark circlemark-lightRed">待</span>
                        <span v-else class="circlemark circlemark-lightGreen">过</span>
                    </p>
                </div>
            </div>
        </div>
          <transition-group class="animated faster" enter-active-class="animated faster slideInRight" leave-active-class="animated faster slideOutRight">
         </transition-group>
    </div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { getPmStandardList, updatePmStandardUser, getPmStandardUserList } from '../../Resources/Api/index'
export default {
    components: {
    },
    data () {
        return {
            scores: 0, // 标准总分数
            pmStandards: [], // 指定阶段的所有标准
            standards: [], // 用户指定阶段的标准和分数
            sd_score1: 0, // sd_id = 27的分数
            sd_score2: 0 // sd_id = 的分数
        }
    },
    created () {
        this.standards = this.$route.query.standards
        if (Number(this.standards.length) > 0) {
            this.standards.forEach(standard => {
                const sdScore = Number(standard.sd_score)
                if (sdScore === 1) {
                    this.scores += 40
                } else if (sdScore === 2) {
                    this.scores += 30
                } else if (sdScore === 3) {
                    this.scores += 20
                } else if (sdScore === 4) {
                    this.scores += 10
                }
            })
        } else {
        }
        this.getPmStandardList()
    },
    methods: {
        ...mapMutations({
            setUpdatePlate: `SET_UPDATE_PLATE`
        }),
        // 查询指定阶段的所有标准
        getPmStandardList () {
            getPmStandardList({
                stId: 2 // 认知阶段
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    this.pmStandards = result.data.Body.pmStandards
                    this.pmStandards.forEach(pmStandard => {
                        // debugger
                        if (this.standards.length === 0) {
                            pmStandard.id = 0
                        } else {
                            this.standards.forEach(standard => {
                                if (pmStandard.sdId === standard.sd_id) {
                                    pmStandard.id = standard.sd_score
                                }
                            })
                        }
                    })
                }
            }).catch(err => {
                console.log('查询指定阶段的所有标准失败getPmStandardList，异常信息：' + err)
            })
        },
        // 修改或者添加用户的标准成绩
        updatePmStandardUser (value) {
            updatePmStandardUser({
                uid: this.leftInfo.uid, // 用户id
                sdId: value.sdId, // 标准id
                sdScore: value.id, // 标准分数
                stId: 2 // 认知阶段
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    layer.msg('提交成功')
                    this.setUpdatePlate()
                    this.getPmStandardUserList()
                }
            }).catch(err => {
                console.log('修改过添加用户标准成绩失败updatePmStandardUser，异常信息：' + err)
            })
        },
        // 查询用户成绩
        getPmStandardUserList () {
            getPmStandardUserList({
                stId: 2, // 阶段id 1-咨询，2-认知，3-考察，4-签约
                uid: this.leftInfo.uid
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    this.standards = result.data.Body.pmStandardUsers
                    if (this.standards.length > 0) {
                        this.scores = 0
                        this.standards.forEach(standard => {
                            const sdScore = Number(standard.sd_score)
                            if (sdScore === 1) {
                                this.scores += 40
                            } else if (sdScore === 2) {
                                this.scores += 30
                            } else if (sdScore === 3) {
                                this.scores += 20
                            } else if (sdScore === 4) {
                                this.scores += 10
                            }
                        })
                    }
                }
            }).catch(err => {
                console.log('查询用户成绩失败getPmStandardUserList，异常信息：' + err)
            })
        }
    },
    computed: {
        ...mapGetters(['leftInfo'])
    },
    watch: {
    }
}

</script>
